//
//  获取新闻api接口
//  SwiftUI+MVVM+Repository
//
//  Created by 高强 on 2024/9/24.
//

import Moya

enum NewsAPI {
    case newsList(pageNum:Int,pageSize:Int,type: String);//type = 0 1 2
}

extension NewsAPI: TargetType {
    
    
    var baseURL: URL {
        return URL(string: AppConfig.shared.baseURL)!
    }
    
    var path: String{
        switch self{
            case .newsList:return "/news/list"
                
        }
    }
    
    var method: Method {
        switch self{
            case .newsList :
                return .get
        }
    }
    
    var task: Task {
        switch self{
            case .newsList(let pageNum,let pageSize,let type):
                return .requestParameters(parameters: [
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "type": type
                ], encoding: URLEncoding.default)
                
        }
    }
    
    var headers: [String : String]? {
        return  ["Content-type": "application/json"]
    }
    
    var sampleData: Data {
        // 在这里提供一个示例数据，用于调试
        return """
            {
                "total": 1,
                "rows": [
                    {
                        "createBy": null,
                        "createTime": "2024-08-07 15:56:20",
                        "updateBy": null,
                        "updateTime": "2024-08-13 16:57:38",
                        "remark": null,
                        "id": 16,
                        "type": 0,
                        "title": "标题",
                        "content": "内容",
                        "delFlag": null
                    }
                ],
                "code": 200,
                "msg": "信息"
            }
            """.data(using: .utf8)!
    }
    
    var validationType: ValidationType {
        return .successCodes
    }
    
}


